package com.globallogic.javatrainings.sergiiivanov.model;

import java.io.Serializable;

import com.globallogic.javatrainings.sergiiivanov.resources.ErrorCodes;

/**
 * Root instance of the model. Encapsulates all model information available via
 * members.
 * 
 * @author Sergey
 * 
 */
public class University implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * Provides access to buildings via {@link BuildingsManager}
     */
    public final BuildingsManager buildings;
    /**
     * Provides access to courses via {@link CoursesManager}
     */
    public final CoursesManager courses;
    /**
     * Provides access to students via {@link StudentsManager}
     */
    public final StudentsManager students;
    /**
     * Provides access to teachers via {@link TeachersManager}
     */
    public final TeachersManager teachers;
    /**
     * Provides access to personnel via {@link PersonnelManager}
     */
    public final PersonnelManager personnel;
    private String title;

    /**
     * Creates new instance of university. Assigns managers.
     * 
     * @param newTitle
     *            - title of the university
     * @throws UniversityWarning
     *             name is null
     */
    public University(String newTitle) throws UniversityWarning {
        setTitle(newTitle);
        buildings = new BuildingsManager();
        courses = new CoursesManager();
        students = new StudentsManager();
        teachers = new TeachersManager();
        personnel = new PersonnelManager();
    }

    /**
     * @return title of the university as it was set on creation or with
     *         {@link #setTitle(String)}
     */
    public String getTitle() {
        return this.title;
    }

    /**
     * Sets new title for university
     * 
     * @param newTitle
     *            - not null title
     * @throws UniversityWarning
     *             title is null
     */
    public void setTitle(String newTitle) throws UniversityWarning {
        if (newTitle == null)
            throw new UniversityWarning(ErrorCodes.UNIVERSITY_EMPTY_NAME);
        this.title = newTitle;
    }
}
